/*******************************************************************************
 * Copyright (c) 2010 Marcelo Cataldo, Sangeeth Nambiar
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * ProjectViewLabelProvider.java
 * 
 * Label provider for the project view (Tree view)
 * 
 * Contributors:
 *    Marcelo Cataldo  - initial implementation 
 *    Sangeeth Nambiar - initial implementation
 *******************************************************************************/
package edu.cmu.isr.dinvenio.ui.views;

import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.plugin.AbstractUIPlugin;

import edu.cmu.isr.dinvenio.Activator;
import edu.cmu.isr.dinvenio.model.DepsGraph;
import edu.cmu.isr.dinvenio.model.DepsGraphLayer;
import edu.cmu.isr.dinvenio.model.DepsGraphNode;
import edu.cmu.isr.dinvenio.model.DepsGraphNodeSet;

public class ProjectViewLabelProvider extends LabelProvider {
	private static final ImageDescriptor IMG_GRAPH = 
	      AbstractUIPlugin.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/brkp_grp.gif");
	
	private static final ImageDescriptor IMG_NODESETS = 
	      AbstractUIPlugin.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/nodesets.gif");
	
	private static final ImageDescriptor IMG_NODESET = 
	      AbstractUIPlugin.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/brkp_type.gif");
	
	private static final ImageDescriptor IMG_NODE =
	      AbstractUIPlugin.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/node.gif");
	
	private static final ImageDescriptor IMG_LAYERS =
	      AbstractUIPlugin.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/links_obj.gif");
	
	private static final ImageDescriptor IMG_LAYER =
	      AbstractUIPlugin.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/layers.gif");
	
	@Override
	public Image getImage(Object element) {
		if(element instanceof DepsGraph) {
			return IMG_GRAPH.createImage();
		}
		else if(element instanceof DepsGraphNodeSet){
			return IMG_NODESET.createImage();
		}
		else if(element instanceof DepsGraphLayer){
			return IMG_LAYER.createImage();
		}
		else if(element instanceof DepsGraphNode){
			return IMG_NODE.createImage();
		}
		else if(element instanceof String){
			if (element.equals("Graph")){
				return IMG_GRAPH.createImage();
			}
			else if(element.equals("Node Set")){
				return IMG_NODESETS.createImage();
			}
			else if(element.equals("Layers")){
				return IMG_LAYERS.createImage();
			}
			else{
				return null;
			}
		}
		return super.getImage(element);
	}

	@Override
	public String getText(Object element) {
		if(element instanceof DepsGraph) {
			return ((DepsGraph)element).toString();
		}
		else if(element instanceof DepsGraphNodeSet){
			return ((DepsGraphNodeSet)element).getId();
		}
		else if(element instanceof DepsGraphLayer){
			return ((DepsGraphLayer)element).getID();
		}
		else if(element instanceof DepsGraphNode){
			return ((DepsGraphNode)element).getId();
		}
		else if(element instanceof String){
			if (element.equals("Graph")){
				return "Dependency Graph";
			}
			else if(element.equals("Node Set")){
				return "Node Sets";
			}
			else if(element.equals("Layers")){
				return "Layers";
			}
			else{
				return null;
			}
		}
		return null;
	}
	

}
